package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//购物车管理
@RestController
public class CartController {

    @Autowired
    private CartService cartService;

    //添加购物车
    @PostMapping("/cart/add")
    public ResultInfo add(@RequestBody Cart cartParam) {//接受参数
        //调用service方法
        Cart cart = cartService.add(cartParam);
        //返回结果
        return ResultInfo.success(cart);
    }

    //查看购物车
    @GetMapping("/cart/list")
    public ResultInfo findList(){
        List<Cart> cartList = cartService.findList();
        return ResultInfo.success(cartList);
    }

    //修改购物车
    @PostMapping("/cart/sub")
    public ResultInfo sub(@RequestBody Cart cartParam){//接收参数
        Cart cart = cartService.sub(cartParam);
       return ResultInfo.success(cart);//返回结果
    }

    //清除购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo clean(){
        cartService.clean();
        return ResultInfo.success();
    }

}
